<template>
<h1>猜数字练习</h1>
  <input type="text" placeholder="请输入你的数字" v-model="num">
  <button @click="guess">猜</button>
  <h3>猜的结果是{{num}}</h3>
</template>
<script setup>
import {ref} from "vue";
const num = ref("");
let x = parseInt(Math.random() * 100)+1;
console.log("答案："+x);

const guess = () => {
  if(num.value > x){
    alert("猜大了")
  }else if(num.value < x){
    alert("猜小了")
  }else{
    alert("恭喜你猜对了")
  }
  num.value = "";
}

</script>


<style scoped>

</style>